package com.ndp.fb.walle.business;

import com.ndp.fb.exception.*;
import com.ndp.fb.model.business.vo.cache.result.AudienceForPublish;
import com.ndp.fb.model.business.vo.cache.result.CustomAudienceCache;
import com.ndp.fb.rdb.model.EntrustAccount;
import com.ndp.fb.rdb.model.Pager;
import com.ndp.fb.rdb.model.User;
import com.ndp.fb.rdb.model.customaudience.CustomAudienceItem;
import com.ndp.fb.rdb.model.customaudience.CustomAudienceTemplate;
import com.ndp.fb.rdb.model.customaudience.CustomAudienceTemplateTable;
import com.ndp.fb.walle.model.bo.customaudiencetemplate.result.CustomAudienceTemplateResult;
import com.ndp.fb.walle.model.vo.OutputResult;
import com.ndp.fb.walle.model.vo.customaudience.param.CustomAudienceDelParam;
import com.ndp.fb.walle.model.vo.customaudience.param.CustomAudienceTemplateParam;
import com.ndp.fb.walle.model.vo.customaudience.param.QueryLookALikeParam;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * Created by Evan on 2015/3/18 11:48.
 */
public interface CustomAudienceTemplateService {

    /**
     * 构建自定义受众缓存
     * @param entrustAccounts
     * @return
     * @throws BusinessException
     */
    List<AudienceForPublish> buildCustomAudienceCaches(List<EntrustAccount> entrustAccounts, Long appId) throws BusinessException;
    List<CustomAudienceCache> buildCustomAudienceCachesFBOK(List<EntrustAccount> entrustAccounts) throws BusinessException;
    
    CustomAudienceCache buildEntrustAccountCustomAudienceCachesFBOK(Long entrustAccountId) throws BusinessException;

    /**
     *
     * @param multipartFile
     * @param contextPath
     * @param customAudienceTemplateParam
     * @param userId
     * @throws FormatException
     * @throws IOException
     */
    int saveCustomAudience(MultipartFile multipartFile,String contextPath, CustomAudienceTemplateParam customAudienceTemplateParam,String userId,Long orgId) throws FormatException, IOException,NotSupportFileSuffixException,ParamException, AudienceSizeIsNotEnoughException;

    /**
     * 自定义受众列表
     */
    Pager<CustomAudienceTemplateResult> getCustomAudienceTemplateList(Long orgId,String userId,String audienceType,String importedType, int firstResult, int sizeNo);

    Pager<CustomAudienceTemplateResult> getLookAlikeList(QueryLookALikeParam queryLookALikeParam, User user, int firstResult, int sizeNo);

    /**
     * 修改自定义受众
     *
     * @param user
     * @param templateId
     * @param multipartFile
     * @param contentPath
     * @param fileType
     * @param editType
     */
    OutputResult update(User user, String templateId, MultipartFile multipartFile, String content,String contentPath,
                String fileType, String editType,String deliverType) throws Exception;
    /**
     * 删除自定义受众
     */
    void del(CustomAudienceDelParam inParam, String userId);

    //删除相似受众
    void delLookAlike(CustomAudienceDelParam inParam, String userId);

    OutputResult updateName(User user, Long templateId, String audienceName);

    /**
     * 根据模板获取自定义受众项列表
     * @param customAudienceTemplateId
     * @return 自定义受众项
     */
    List<CustomAudienceItem> getCustomAudienceItemList(String userId,Long customAudienceTemplateId);

    /**
     * 查找公司下所有可用自定义受众模板
     */
    List<CustomAudienceTemplate> findByOrgId(Long orgId, String userId);

    List<Long> findHasLookALike(List<Long> ids);

    /**
     * 受众创建重试
     */
    void retryCustomAudience(Long tmplId, Long fbAccountId, Long customAudienceDbId, String userId);

    /**
     * 获取全部自定义受众模板
     * @param orgId
     * @param audienceType
     * @param importedType
     * @return
     */
    List<CustomAudienceTemplateTable> getAllCustomAudienceTemplate(Long orgId, String audienceType, String importedType);

    /**
     * 获取全部相似受众列表
     * @param queryLookALikeParam
     * @param user
     * @return
     */
    List<CustomAudienceTemplateTable> getAllLookAlikeList(QueryLookALikeParam queryLookALikeParam, User user);
}
